package com.daye.homework.service.impl;

import com.daye.homework.bean.Class;
import com.daye.homework.bean.Student;
import com.daye.homework.dao.AdminDao;
import com.daye.homework.factory.AdminDaoFactory;
import com.daye.homework.service.AdminService;

import java.sql.SQLException;
import java.util.List;

public class AdminServiceImpl implements AdminService {

    private AdminDao adminDao = AdminDaoFactory.getAdminDao();

    /**
     * 管理员登录
     *
     * @param username
     * @param password
     * @return
     */
    @Override
    public boolean adminLogin(String username, String password) {
        return adminDao.findAdmin(username , password);
    }

    /**
     * 添加学生
     *
     * @param student
     */
    @Override
    public void addStudent(Student student) throws SQLException {
        adminDao.insertStudent(student);
    }

    /**
     * 遍历所有学生
     *
     * @return
     */
    @Override
    public List<Student> getAllStudent() throws SQLException {
        return adminDao.selectAllStudent();
    }

    /**
     * 根据id删除学生
     *
     * @param id
     */
    @Override
    public void deleteStudentById(Integer id) throws SQLException {
        adminDao.removeStudentById(id);
    }

    /**
     * 根据学号寻找学员
     *
     * @param id
     * @return
     */
    @Override
    public Student getStudentById(int id) throws SQLException {
        return adminDao.selectStudentById(id);
    }

    /**
     * 根据id修改学员信息
     *
     * @param student
     */
    @Override
    public void updateStudentById(Student student) throws SQLException {
        adminDao.updateStudentById(student);
    }

    /**
     * 新建班级
     *
     * @param newClass
     */
    @Override
    public void addClass(Class newClass) throws SQLException {
        adminDao.insertClass(newClass);
    }

    /**
     * 遍历所有班级
     *
     * @return
     */
    @Override
    public List<Class> getAllClass() throws SQLException {
        return adminDao.selectAllClass();
    }

    /**
     * 根据id删除班级
     *
     * @param id
     */
    @Override
    public void deleteClassById(Integer id) throws SQLException {
        adminDao.removeClassById(id);
    }

    /**
     * 根据id查找班级
     *
     * @param id
     * @return
     */
    @Override
    public Class getClassById(int id) throws SQLException {
        return adminDao.selectClassById(id);
    }

    /**
     * 根据id修改班级信息
     *
     * @param myClass
     */
    @Override
    public void updateClassById(Class myClass) throws SQLException {
        adminDao.updateClassById(myClass);
    }

    /**
     * 改变班级人数
     *
     * @param id
     * @param i
     */
    @Override
    public void updateClassPeopleNumById(int id, int i) throws SQLException {
        adminDao.updateClassPeopleNumById(id , i);
    }
}
